
//中级，有点难。
var reverseBetween = function(head, left, right) {
    if(left == right){
        return head
    }
    let soilder = {
        next:head
    }
    let tmp = soilder
    for(let i=0;i<left-1;i++){//让当前节点先走到left位置
        tmp = tmp.next
    }

    let prev = tmp.next
    let cur = prev.next


    for(let j=0;j<right-left;j++){//开始反转链表  这是核心逻辑没有变
        let next = cur.next
        cur.next = prev
        prev = cur
        cur = next
    }   
    // 反转完指定位置后没有反转的要修正指向  1-》4   2-》5
    tmp.next.next = cur //让2-》5
    tmp.next = prev//让1-》4

return soilder.next
};

// image.png